<?php 
class Forums extends E_Entity 
{
	public   $table =array(
					"id" =>"id",
					"version"=>"version",
					"userid" =>"userid",
					"modid" =>"modid",
					"title" =>"title",
					"content" =>"content",  
					"sign" =>"sign",
					"status" =>"status",
					"ctime" =>"ctime",
					"mtime" =>"mtime"
					);
					
	public function getTableName()
	{
		return "micro_forum";
	}
	public function getJoinMap()
	{
		$map = array("mapUser" =>array("Entity"=>"Users","Method"=>"getById", "param"=>"userid"),
					 "mapCommentCount"=>array("Entity"=>"Comments","Method"=>"getCount","param"=>"id")
						);
		return $map;
	}	
	public static function insertEntity($row)
	{	
		$entity = new self();
	 	return $entity->createEntityForRow($row);
	}
	public static function getById($id)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['id']} = :id";
		return $entity->getEntityByIndexKey($sql, $id, array("id"=>$id));
	}
	public static function getByModId($modid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['modid']} = :modid";
		return $entity->getEntityByIndexKey($sql, $id, array("modid"=>$modid));
	}
	public static function getCount($modid)
	{
		$entity = new self();
		$db = $entity->getDbHandle();
		$row = $db->fetch("select count(1) as num from {$entity->getTableName()} where modid ='$modid'");
		return $row['num'];
	}
	public static function getListByModId($modid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['modid']} = :modid";
		return $entity->birthEntity($sql, array("modid"=>$modid));
	}
	public static function getList()
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} ";
		return $entity->birthEntity($sql);
	}
	public function getCtime($Ymd = "Y-m-d H:i:s")
	{
		return date($Ymd, $this->ctime);
	}
	public  function getContent()
	{
		$content = $this->content;
		return regUBB(regExpContent($content,500, 500));
	}
}
?>